﻿<UserControl x:Class="Stopwatch.View.BasicStopwatch"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             xmlns:viewmodel="clr-namespace:Stopwatch.ViewModel">

    <UserControl.Resources>
        <viewmodel:StopwatchViewModel x:Key="viewModel"/>
        <viewmodel:TimeNumberFormatConverter x:Key="timeNumberFormatConverter"/>
        <viewmodel:BooleanVisibilityConverter x:Key="visibilityConverter"/>
        <viewmodel:BooleanNotConverter x:Key="notConverter"/>
    </UserControl.Resources>

    <Grid DataContext="{StaticResource ResourceKey=viewModel}">
        <StackPanel>
            <TextBlock>
                <Run>Elapsed time: </Run>
                <Run Text="{Binding Hours, Mode=OneWay,
                    Converter={StaticResource timeNumberFormatConverter}}"/>
                <Run>:</Run>
                <Run Text="{Binding Minutes, Mode=OneWay,
                    Converter={StaticResource timeNumberFormatConverter}, ConverterParameter=d2}"/>
                <Run>:</Run>
                <Run Text="{Binding Seconds, Mode=OneWay,
                    Converter={StaticResource timeNumberFormatConverter}}"/>
            </TextBlock>
            <TextBlock>
                <Run>Lap time: </Run>
                <Run Text="{Binding LapHours, Mode=OneWay,
                    Converter={StaticResource timeNumberFormatConverter}}"/>
                <Run>:</Run>
                <Run Text="{Binding LapMinutes, Mode=OneWay,
                    Converter={StaticResource timeNumberFormatConverter}, ConverterParameter=d2}"/>
                <Run>:</Run>
                <Run Text="{Binding LapSeconds, Mode=OneWay,
                    Converter={StaticResource timeNumberFormatConverter}}"/>
            </TextBlock>
            <StackPanel Orientation="Horizontal">
                <Button IsEnabled="{Binding Running, Converter={StaticResource notConverter}}"
                        Click="StartButton_Click" Margin="0,0,5,0">Start</Button>
                <Button IsEnabled="{Binding Running}" Click="StopButton_Click"
                        Margin="0,0,5,0">Stop</Button>
                <Button Click="ResetButton_Click" Margin="0,0,5,0">Reset</Button>
                <Button IsEnabled="{Binding Running}" Click="LapButton_Click">Lap</Button>
            </StackPanel>
            <TextBlock Text="Stopwatch is running"
                Visibility="{Binding Running, Converter={StaticResource visibilityConverter}}"/>
        </StackPanel>
    </Grid>
</UserControl>